import { Component, OnInit, Input } from '@angular/core';
import { MerchantService } from '../../service/merchant.service';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-merchant',
  templateUrl: './merchant.component.html',
  styleUrls: ['./merchant.component.scss'],
  providers: [MerchantService]
})
export class MerchantComponent implements OnInit {
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  dataSet: Array<any> = [];
  loading = true;
  isOkLoading = false;
  isVisible = false;
  name: any;
  agentid: any;
  constructor(private service: MerchantService, private ar: ActivatedRoute) {
    this.agentid = this.ar.snapshot.params.id;
  }

  ngOnInit() {
    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.service.query({
      offset: this.pageIndex,
      limit: this.pageSize,
      agent: this.agentid
    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows;
      this.isVisible = true;
    });
  }
}
